package cn.zlp.test;

import cn.zlp.basic.BaseTest;
import cn.zlp.pet.domain.Pet;
import cn.zlp.pet.domain.PetDetail;
import cn.zlp.pet.mapper.PetDetailMapper;
import cn.zlp.pet.mapper.PetMapper;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import java.math.BigDecimal;

public class CreatePet extends BaseTest {

    @Autowired(required = false)
    private PetMapper petMapper;

    @Autowired(required = false)
    private PetDetailMapper petDetailMapper;

    @Test
    public void test1() throws Exception{
        Pet pet = petMapper.loadById(472L);
        PetDetail petDetail = petDetailMapper.loadByPetId(pet.getId());

        for(int i = 0;i<100;i++){
            if(i%2==0){
                pet.setId(null);//自增长
                petDetail.setId(null);
                pet.setName("小猪佩奇" + i);
                pet.setState(1); // 上架
                pet.setShop_id(27L);
                pet.setOffsaletime(null);
                pet.setOnsaletime(null);

                pet.setSaleprice(new BigDecimal(i*10));
                pet.setCostprice(new BigDecimal(i*5));

                petMapper.save(pet);
                petDetail.setPet_id(pet.getId());
                petDetailMapper.save(petDetail);
            }else{
                pet.setId(null);//自增长
                petDetail.setId(null);
                pet.setName("野猪乔治" + i);
                pet.setState(0);
                pet.setShop_id(27L);
                pet.setOffsaletime(null);
                pet.setOnsaletime(null);
                pet.setSaleprice(new BigDecimal(i*10));
                pet.setCostprice(new BigDecimal(i*5));

                petMapper.save(pet);
                petDetail.setPet_id(pet.getId());
                petDetailMapper.save(petDetail);
            }
        }
    }


}
